<?php
/*******************************************************************************
date must be convered to yyyy-mm-dd format
time must be converted to hh:mm format
*******************************************************************************/

	require_once "Date.php";
	require_once "events.php";
	
	$client = $_SESSION['client'];
	$title = $_POST['eventname'];
	$desc= $_POST['eventdesc'];
	$where = $_POST['eventloc'];
	$startDate = slashedDateToDb($_POST['eventsdate']);
	$startTime = setMilitaryTime($_POST['eventstime']);
	$endDate = slashedDateToDb($_POST['eventedate']);
	$endTime = setMilitaryTime($_POST['eventetime']);
	$tzOffset = '-07';
	$allday = $_POST['allDay'];
	
	
	$calID = $_POST['addeventcal'];
	echo $calID."<BR>";
	
	
	$symbolLoc = stripos($calID, "%40");
	$calID = substr($calID, 0, $symbolLoc);
	$preLoc = stripos($calID, "t/");
	$calID = substr($calID, $preLoc+2);
	
	if (strlen($calID) <= 20)
		$calendar=false;
	else
		$calendar='http://www.google.com/calendar/feeds/'.$calID.'@group.calendar.google.com/private/full';
	echo $calendar;
	
//	$calendar = 'http://www.google.com/calendar/feeds/'.$_POST['addeventcal'].'@group.calendar.google.com/private/full';
//	$calendar = 'http://www.google.com/calendar/feeds/8f269i69mj0tdaojlml4jl9u5s@group.calendar.google.com/private/full';
	
	//echo "$title, $desc, $where, $startDate, $startTime, $endDate, $endTime, $tzOffset";
	if (!$allday){
		createEvent ($client, $title, $desc, $where, $startDate, $startTime, $endDate, $endTime, $tzOffset, $calendar);
	}else{
		createEvent ($client, $title, $desc, $where, $startDate, '', $endDate, '', $tzOffset, $calendar);
	}
	
	header("location:viewMonth.php");
?>
